package com.jkc.xh.views.headview;

import android.content.ClipboardManager;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jkc.xh.MainApplication;
import com.jkc.xh.R;
import com.jkc.xh.models.BankCardModel;
import com.jkc.xh.utils.ImageLoader;
import com.jkc.xh.views.widget.ToastUtil;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by zhangbreeze on 2015/11/13.
 */
@EViewGroup(R.layout.item_bank_card)
public class BankCardView extends RelativeLayout {

    @ViewById
    ImageView bankIcon;
    @ViewById
    TextView bankAddress;
    @ViewById
    TextView bankAccount;
    @ViewById
    TextView bankAccountAuth;
    private ClipboardManager myClipboard;

    public BankCardView(Context context) {
        this(context, null);
    }

    public BankCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        myClipboard = (ClipboardManager) MainApplication.getInstance().getSystemService(Context.CLIPBOARD_SERVICE);
    }

    public void loadInfo(BankCardModel model) {
        bankAddress.setText(model.bank_name);
        bankAccountAuth.setText(model.bank_realname);
        bankAccount.setText(model.bank_card);
        ImageLoader.loadImage(model.logo, bankIcon);
        bankAccount.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String bankCardStr = bankAccount.getText().toString();
                if (bankCardStr == null) {
                    return;
                }
                myClipboard.setText(bankCardStr.replaceAll("\\s*", ""));
                ToastUtil.showToastShort("银行卡号已经复制到黏贴板!");
            }
        });
        bankAccountAuth.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                myClipboard.setText(bankAccountAuth.getText());
                ToastUtil.showToastShort("户名已经复制到黏贴板!");
            }
        });
        bankAddress.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                myClipboard.setText(bankAddress.getText());
                ToastUtil.showToastShort("开户行已经复制到黏贴板!");
            }
        });
    }

}
